<template>
    <div class="Organization-container content-wrapper">
        <el-row :gutter="20">
            <el-col :span="8">
                <!--公司-->
                <el-row class="margin-bottom-10">
                    <el-col>
                        <el-card class="box-card" :body-style="{ padding: '0px' }">
                            <div class="clearfix card-header">
                                <span><i class="el-icon-menu" style="color:#324057"></i> 公司管理</span>
                                <el-button @click="handleReloadCompany" icon="el-icon-refresh" style="float: right; padding: 5px 0px 0px 3px" type="text"></el-button>
                                <el-button @click="handleDeleteCompany" icon="el-icon-delete" style="float: right; padding: 5px 10px 0px 3px" type="text"></el-button>
                                <el-button @click="handleUpdateCompany" icon="el-icon-edit" style="float: right; padding: 5px 0px 0px 3px" type="text"></el-button>
                                <el-button @click="handleCreateCompany" icon="el-icon-plus" style="float: right; padding: 5px 0px 0px 3px" type="text"></el-button>
                            </div>
                            <el-tree :data="treeCompany" node-key="id" ref="tree"
                                     v-loading="loadingCompany"
                                     highlight-current
                                     :check-strictly="true"
                                     :default-expand-all="false"
                                     :props="defaultProps"
                                     :default-expanded-keys="expandedKeyCompany"
                                     @node-click="handleNodeClickCompany"
                            ></el-tree>
                        </el-card>
                    </el-col>
                </el-row>

                <!--部门-->
                <el-row class="margin-bottom-10">
                    <el-col>
                        <el-card class="box-card" :body-style="{ padding: '0px' }">
                            <div class="clearfix card-header">
                                <span><i class="el-icon-menu" style="color:#324057"></i> 部门管理</span>
                                <el-button @click="handleReloadDepartment" icon="el-icon-refresh" style="float: right; padding: 5px 0px 0px 3px" type="text"></el-button>
                                <el-button @click="handleDeleteDepartment" icon="el-icon-delete" style="float: right; padding: 5px 10px 0px 3px" type="text"></el-button>
                                <el-button @click="handleUpdateDepartment" icon="el-icon-edit" style="float: right; padding: 5px 0px 0px 3px" type="text"></el-button>
                                <el-button @click="handleCreateDepartment" icon="el-icon-plus" style="float: right; padding: 5px 0px 0px 3px" type="text"></el-button>
                            </div>
                            <el-tree :data="treeDepartment" node-key="id" ref="tree"
                                     v-loading="loadingDepartment"
                                     highlight-current
                                     :check-strictly="true"
                                     :default-expand-all="false"
                                     :props="defaultProps"
                                     :default-expanded-keys="expandedKeyDepartment"
                                     @node-click="handleNodeClickDepartment"
                            ></el-tree>
                        </el-card>
                    </el-col>
                </el-row>
            </el-col>


            <el-col :span="16">
                <div class="filter-wrapper">
                    <el-form ref="filterForm" :model="listQuery" :inline="true">

                        <el-form-item prop="realName" size="medium">
                            <el-input v-model="listQuery.realName" placeholder="姓名"></el-input>
                        </el-form-item>

                        <el-form-item prop="account" size="medium">
                            <el-input v-model="listQuery.account" placeholder="账号"></el-input>
                        </el-form-item>

                        <el-form-item prop="sex" size="medium">
                            <el-select v-model="listQuery.sex" placeholder="性别" clearable style="width: 100px">
                                <el-option
                                        v-for="item in sexOptions"
                                        :key="item.key"
                                        :label="item.label"
                                        :value="item.key">
                                </el-option>
                            </el-select>
                        </el-form-item>

                        <el-form-item prop="status" size="medium">
                            <el-select v-model="listQuery.status" placeholder="状态" clearable style="width: 100px">
                                <el-option
                                        v-for="item in statusOptions"
                                        :key="item.key"
                                        :label="item.label"
                                        :value="item.key">
                                </el-option>
                            </el-select>
                        </el-form-item>

                        <el-form-item prop="orderBy" size="medium">
                            <el-select v-model="listQuery.orderBy" placeholder="排序" clearable style="width: 120px">
                                <el-option
                                        v-for="item in sortOptions"
                                        :key="item.key"
                                        :label="item.label"
                                        :value="item.key">
                                </el-option>
                            </el-select>
                        </el-form-item>

                        <div class="toolbar">
                            <el-button type="primary" size="medium" icon="el-icon-search" @click="handleFilter">搜索</el-button>
                            <el-button type="primary" size="medium" icon="el-icon-mars-reset" @click="handleResetFilter">重置</el-button>
                            <el-button type="danger" size="medium" icon="el-icon-delete" @click="handleBatchDelete">移除</el-button>
                        </div>
                    </el-form>
                </div>

                <el-table
                        :data="list"
                        border fit
                        highlight-current-row
                        v-loading="listLoading"
                        element-loading-text="给我一点时间"
                        @selection-change="handleSelectionChange">

                    <el-table-column
                            type="selection"
                            width="55" align="center">
                    </el-table-column>
                    <el-table-column type="index" width="55" align="center"></el-table-column>


                    <el-table-column label="姓名" width="110px" align="center">
                        <template slot-scope="scope"> {{scope.row.realName}} </template>
                    </el-table-column>

                    <el-table-column label="性别" width="80px" align="center">
                        <template slot-scope="scope">
                            <el-tag type="primary" v-if="scope.row.sex === 1">男</el-tag>
                            <el-tag type="danger" v-else-if="scope.row.sex === 2">女</el-tag>
                            <el-tag type="info" v-else>未知</el-tag>
                        </template>
                    </el-table-column>

                    <el-table-column label="账号" width="110px" align="center">
                        <template slot-scope="scope"> {{scope.row.account}} </template>
                    </el-table-column>

                    <el-table-column label="手机号码" width="130px" align="center">
                        <template slot-scope="scope"> {{scope.row.mobile}} </template>
                    </el-table-column>

                    <el-table-column label="邮件地址" min-width="200px" align="center" show-overflow-tooltip>
                        <template slot-scope="scope"> {{scope.row.email}} </template>
                    </el-table-column>

                    <el-table-column label="状态" width="80px" align="center">
                        <template slot-scope="scope">
                            <el-tag type="success" v-if="scope.row.status === 1">正常</el-tag>
                            <el-tag type="danger" v-else>禁用</el-tag>
                        </template>
                    </el-table-column>

                    <el-table-column label="创建时间" width="150px" align="center">
                        <template slot-scope="scope"> {{scope.row.ctime | parseTime('{y}-{m}-{d} {h}:{i}')}} </template>
                    </el-table-column>
                    <el-table-column label="最后修改时间" width="150px" align="center">
                        <template slot-scope="scope"> {{scope.row.utime | parseTime('{y}-{m}-{d} {h}:{i}')}} </template>
                    </el-table-column>

                    <el-table-column label="操作" fixed="right" width="110px" align="center">
                        <template slot-scope="scope">
                            <el-button size="small" type="danger" icon="delete" @click="handleDelete(scope.row)">移除</el-button>
                        </template>
                    </el-table-column>
                </el-table>

                <div v-show="!listLoading" class="pagination-container">
                    <el-pagination
                            @size-change="handleSizeChange"
                            @current-change="handleCurrentChange"
                            :current-page="listQuery.page"
                            :page-sizes="[10, 20, 30, 50]"
                            :page-size="listQuery.rows"
                            layout="total, sizes, prev, pager, next, jumper"
                            :total="total">
                    </el-pagination>
                </div>
            </el-col>
        </el-row>

        <!--公司表单-->
        <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisibleCompany" :close-on-click-modal="false" :close-on-press-escape="false" @close="handleCloseDialogCompany">
            <el-row>
                <el-col :md="6" :lg="6">
                    <el-tree :data="treeCompany"
                             node-key="id"
                             highlight-current
                             :default-expanded-keys="expandedKeyDialog"
                             :props="defaultProps"
                             @node-click="handleSetParentCompany"></el-tree>
                </el-col>
                <el-col :md="6" :lg="6">
                    <el-form :model="formCompany" ref="formCompany" :rules="CompanyRules" labelPosition="right" labelWidth="80px" style="width: 400px">

                        <el-form-item label="所属上级">
                            <el-input v-model="formCompany.parentName" placeholder="请选择所属上级" readonly >
                                <i class="el-icon-close el-input__icon" slot="suffix" @click="handleIconClickCompany"></i>
                            </el-input>
                        </el-form-item>

                        <el-form-item label="名称" prop="name">
                            <el-input v-model="formCompany.name"></el-input>
                        </el-form-item>

                        <el-form-item label="编码" prop="code">
                            <el-input v-model="formCompany.code"></el-input>
                        </el-form-item>

                        <el-form-item label="备注">
                            <el-input
                                    type="textarea"
                                    :autosize="{ minRows: 2, maxRows: 4}"
                                    placeholder="请输入内容"
                                    v-model="formCompany.remarks">
                            </el-input>
                        </el-form-item>
                    </el-form>
                </el-col>
            </el-row>

            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisibleCompany = false">取 消</el-button>
                <el-button v-if="dialogStatus == 'create'" type="primary" @click="createCompany">确 定</el-button>
                <el-button v-else="" type="primary" @click="updateCompany">确 定</el-button>
            </div>
        </el-dialog>


        <!--部门表单-->
        <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisibleDepartment" :close-on-click-modal="false" :close-on-press-escape="false" @close="handleCloseDialogDepartment">
            <el-row>
                <el-col :md="6" :lg="6">
                    <el-tree :data="treeDepartment"
                             node-key="id"
                             highlight-current
                             :default-expanded-keys="expandedKeyDialog"
                             :props="defaultProps"
                             @node-click="handleSetParentDepartment"></el-tree>
                </el-col>
                <el-col :md="6" :lg="6">
                    <el-form :model="formDepartment" ref="formDepartment" :rules="DepartmentRules" labelPosition="right" labelWidth="80px" style="width: 400px">

                        <el-form-item label="所属公司" >
                            <el-input v-model="formDepartment.companyName" readonly></el-input>
                        </el-form-item>

                        <el-form-item label="所属上级">
                            <el-input v-model="formDepartment.parentName" placeholder="请选择所属上级" readonly >
                                <i class="el-icon-close el-input__icon" slot="suffix" @click="handleIconClickDepartment"></i>
                            </el-input>
                        </el-form-item>

                        <el-form-item label="名称" prop="name">
                            <el-input v-model="formDepartment.name"></el-input>
                        </el-form-item>

                        <el-form-item label="编码" prop="code">
                            <el-input v-model="formDepartment.code"></el-input>
                        </el-form-item>

                        <el-form-item label="备注">
                            <el-input
                                    type="textarea"
                                    :autosize="{ minRows: 2, maxRows: 4}"
                                    placeholder="请输入内容"
                                    v-model="formDepartment.remarks">
                            </el-input>
                        </el-form-item>
                    </el-form>
                </el-col>
            </el-row>

            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisibleDepartment = false">取 消</el-button>
                <el-button v-if="dialogStatus == 'create'" type="primary" @click="createDepartment">确 定</el-button>
                <el-button v-else="" type="primary" @click="updateDepartment">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
    import {
        created as createdCompany,
        updated as updatedCompany,
        deleted as deletedCompany,
        selectOne as selectOneCompany,
        selectTree as selectTreeCompany } from '@/api/upms/company'
    import {
        created as createdDepartment,
        updated as updatedDepartment,
        deleted as deletedDepartment,
        selectOne as selectOneDepartment,
        selectTree as selectTreeDepartment,
        remove_department_user } from '@/api/upms/department'

    import { selectList } from '@/api/upms/user'

    const sexOptions = [{label: '男', key: 1}, {label: '女', key: 2}, {label: '未知', key: 3}]
    const sortOptions = [{label: '按ID升序', key: 'id asc'}, {label: '按ID降序', key: 'id desc'}]
    const statusOptions = [{label: '正常', key: 1}, {label: '锁定', key: 2}]
    export default {
        name: 'Organization',
        data() {
            return {
                defaultProps: {
                    label: 'name',
                    children: 'children'
                },
                textMap: {
                    create: '新增',
                    update: '编辑'
                },
                dialogStatus: '',
                expandedKeyDialog: [0],

                /************************公司************************/
                treeCompany: [],
                loadingCompany: false,
                dialogFormVisibleCompany: false,
                expandedKeyCompany: [0],
                formCompany: {
                    id: '',
                    pid: '',
                    name: '',
                    code: '',
                    remarks: '',
                    parentName: ''
                },
                detailCompany: {
                    id: '',
                    pid: '',
                    name: '',
                    code: '',
                    remarks: '',
                    parentName: ''
                },

                /************************部门************************/
                treeDepartment: [],
                loadingDepartment: false,
                dialogFormVisibleDepartment: false,
                expandedKeyDepartment: [0],
                formDepartment: {
                    id: '',
                    pid: '',
                    name: '',
                    code: '',
                    remarks: '',
                    parentName: '',
                    companyId: '',
                    companyName: ''
                },
                detailDepartment: {
                    id: '',
                    pid: '',
                    name: '',
                    code: '',
                    remarks: '',
                    parentName: '',
                    companyId: '',
                    companyName: ''
                },

                /************************用户列表************************/
                list: [],
                total: null,
                listLoading: false,
                multipleSelection: [],
                listQuery: {
                    page: 1,
                    rows: 10,
                    roleId: this.$route.query.roleId,
                    account: undefined,
                    realName: undefined,
                    status: undefined,
                    sex: undefined,
                    orderBy: 'id asc'
                },
                sexOptions,
                statusOptions,
                sortOptions,
                CompanyRules: {
                    name: [
                        { required: true, message: '请输入名称', trigger: 'blur' }
                    ],
                    code: [
                        { required: true, message: '请输入编码', trigger: 'blur' }
                    ]
                },
                DepartmentRules: {
                    name: [
                        { required: true, message: '请输入名称', trigger: 'blur' }
                    ],
                    code: [
                        { required: true, message: '请输入编码', trigger: 'blur' }
                    ]
                }
            }
        },
        created() {
            this.getTreeDataCompany()
        },
        methods: {
            /************************公司************************/
            handleNodeClickCompany(data, node) {
                this.detailCompany = data
                this.detailCompany['parentName'] = node.parent.data.name

                this.formDepartment.companyId = data.id
                this.formDepartment.companyName = data.name
                this.getTreeDataDepartment()

                this.listQuery.companyId = data.id
                this.listQuery.departmentId = null
                this.getTableData()
            },
            handleCreateCompany() {//添加数据窗口
                this.dialogStatus = 'create'
                this.dialogFormVisibleCompany = true
            },
            handleUpdateCompany() {//修改数据窗口
                if(this.detailCompany.id) {
                    selectOneCompany(this.detailCompany.id).then(response => {
                        this.dialogStatus = 'update'
                        this.dialogFormVisibleCompany = true
                        this.formCompany = Object.assign({}, response.data)
                        this.formCompany['parentName'] = this.detailCompany.parentName
                        this.expandedKeyEdit = [this.detailCompany.id]
                    })
                } else {
                    this.$message({ type: 'warning', message: '请选择需要修改的菜单' })
                }
            },
            handleDeleteCompany() {//删除数据
                if(this.detailCompany.id) {
                    this.$confirm('确定要删除？', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        deletedCompany(this.detailCompany.id).then(response => {
                            if(response.data.status) {
                                this.$notify({
                                    title: '成功', message: response.data.message,
                                    type: 'success', duration: 2000
                                })
                                this.getTreeDataCompany()
                                this.treeDepartment = []
                            } else {
                                this.$notify({
                                    title: '发生错误', message: response.data.message,
                                    type: 'error', duration: 2000
                                })
                            }
                        })
                    }).catch(() => {
                        this.$message({ type: 'info', message: '已取消删除' })
                    })
                } else {
                    this.$message({ type: 'warning', message: '请选择需要删除的菜单' })
                }
            },
            createCompany() {//添加数据
                this.$refs['formCompany'].validate((valid) => {
                    if(valid) {
                        createdCompany(this.formCompany).then(response => {
                            if(response.data.status) {
                                this.$notify({
                                    title: '成功', message: response.data.message,
                                    type: 'success', duration: 2000
                                })
                                this.getTreeDataCompany()
                                this.dialogFormVisibleCompany = false
                            } else {
                                this.$notify({
                                    title: '操作失败', message: response.data.message,
                                    type: 'error', duration: 2000
                                })
                            }
                        })
                    }
                })
            },
            updateCompany() {//修改数据
                this.$refs['formCompany'].validate((valid) => {
                    if(valid) {
                        updatedCompany(this.formCompany).then(response => {
                            if(response.data.status) {
                                this.$notify({
                                    title: '成功', message: response.data.message,
                                    type: 'success', duration: 2000
                                })

                                this.detailCompany = Object.assign({}, this.form)
                                this.getTreeDataCompany()
                                this.dialogFormVisibleCompany = false
                            } else {
                                this.$notify({
                                    title: '发生错误', message: response.data.message,
                                    type: 'error', duration: 2000
                                })
                            }
                        })
                    }
                })
            },
            getTreeDataCompany() {//获取数据列表
                this.loadingCompany = true
                selectTreeCompany().then(response => {
                    this.treeCompany = response.data
                    this.loadingCompany = false
                }).catch(error => {
                    console.log(error)
                    this.loadingCompany = false
                })
            },
            handleSetParentCompany(data, node) {
                var shut = false
                var sf = this.formCompany

                //判断是否选择自己作为上级
                if(this.formCompany.id == data.id) {
                    this.$message({
                        title: '提示', message: '选择所属上级有误',
                        type: 'info', duration: 2000
                    })
                    return
                }
                //判断选择的上级是否当前修改的上级
                res(node)
                function res(node) {
                    if(!shut) {
                        var n = node.parent
                        if(null != n) {
                            if(sf.id == n.data.id || sf.id == n.data.pid) {
                                shut = true
                            }
                            res(n)
                        }
                    }
                }
                if(shut == true) {
                    this.$message({
                        title: '提示', message: '选择所属上级有误',
                        type: 'warning', duration: 2000
                    })
                    return
                }

                this.formCompany = Object.assign({}, this.formCompany)
                this.formCompany['pid'] = data.id
                this.formCompany['parentName'] = data.name
            },
            handleIconClickCompany(ev) {
                this.formCompany = Object.assign({}, this.formCompany)
                this.formCompany['pid'] = ''
                this.formCompany['parentName'] = ''
            },
            handleCloseDialogCompany() {
                this.resetFormCompany()
            },
            handleReloadCompany(){
                this.getTreeDataCompany()
            },
            resetFormCompany() {
                if(this.$refs['formCompany']) {
                    this.$refs['formCompany'].resetFields()
                }
                this.formCompany = {
                    id: '',
                    pid: '',
                    name: '',
                    type: '',
                    code: '',
                    url: '',
                    status: '',
                    orders: '',
                    remarks: '',
                    parentName: ''
                }

            },

            /************************部门************************/
            handleNodeClickDepartment(data, node) {
                this.detailDepartment = data
                this.detailDepartment['parentName'] = node.parent.data.name

                this.listQuery.departmentId = data.id
                this.getTableData()
            },
            handleCreateDepartment() {//添加数据窗口
                this.dialogStatus = 'create'
                this.dialogFormVisibleDepartment = true
            },
            handleUpdateDepartment() {//修改数据窗口
                if(this.detailDepartment.id) {
                    selectOneDepartment(this.detailDepartment.id).then(response => {
                        this.dialogStatus = 'update'
                        this.dialogFormVisibleDepartment = true
                        this.formDepartment = Object.assign({}, response.data, {companyId: this.formDepartment.companyId, companyName: this.formDepartment.companyName})
                        this.formDepartment['parentName'] = this.detailDepartment.parentName
                        this.expandedKeyEdit = [this.detailDepartment.id]
                    })
                } else {
                    this.$message({ type: 'warning', message: '请选择需要编辑的部门' })
                }
            },
            handleDeleteDepartment() {//删除数据
                if(this.detailDepartment.id) {
                    this.$confirm('确定要删除？', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        deletedDepartment(this.detailDepartment.id).then(response => {
                            if(response.data.status) {
                                this.$notify({
                                    title: '成功', message: response.data.message,
                                    type: 'success', duration: 2000
                                })
                                this.getTreeDataDepartment()
                            } else {
                                this.$notify({
                                    title: '发生错误', message: response.data.message,
                                    type: 'error', duration: 2000
                                })
                            }
                        })
                    }).catch(() => {
                        this.$message({ type: 'info', message: '已取消删除' })
                    })
                } else {
                    this.$message({ type: 'warning', message: '请选择需要删除的部门' })
                }
            },
            createDepartment() {//添加数据
                this.$refs['formDepartment'].validate((valid) => {
                    if(valid) {
                        console.log()
                        if(this.formDepartment.companyId) {
                            createdDepartment(this.formDepartment).then(response => {
                                if(response.data.status) {
                                    this.$notify({
                                        title: '成功', message: response.data.message,
                                        type: 'success', duration: 2000
                                    })
                                    this.getTreeDataDepartment()
                                    this.dialogFormVisibleDepartment = false
                                } else {
                                    this.$notify({
                                        title: '操作失败', message: response.data.message,
                                        type: 'error', duration: 2000
                                    })
                                }
                            })
                        } else {
                            this.$message({ type: 'warning', message: '请选择所属公司' })
                        }
                    }
                })
            },
            updateDepartment() {//修改数据
                this.$refs['formDepartment'].validate((valid) => {
                    if(valid) {
                        updatedDepartment(this.formDepartment).then(response => {
                            if(response.data.status) {
                                this.$notify({
                                    title: '成功', message: response.data.message,
                                    type: 'success', duration: 2000
                                })

                                this.detailDepartment = Object.assign({}, this.form)
                                this.getTreeDataDepartment()
                                this.dialogFormVisibleDepartment = false
                            } else {
                                this.$notify({
                                    title: '发生错误', message: response.data.message,
                                    type: 'error', duration: 2000
                                })
                            }
                        })
                    }
                })
            },
            getTreeDataDepartment() {//获取数据列表
                if(this.formDepartment.companyId) {
                    this.loadingDepartment = true
                    selectTreeDepartment({companyId: this.formDepartment.companyId}).then(response => {
                        this.treeDepartment = response.data
                        this.loadingDepartment = false
                    }).catch(error => {
                        console.log(error)
                        this.loadingDepartment = false
                    })
                } else {
                    this.$message({ type: 'warning', message: '请选择所属公司' })
                }

            },
            handleSetParentDepartment(data, node) {
                var shut = false
                var sf = this.formDepartment

                //判断是否选择自己作为上级
                if(this.formDepartment.id == data.id) {
                    this.$message({
                        title: '提示', message: '选择所属上级有误',
                        type: 'info', duration: 2000
                    })
                    return
                }
                //判断选择的上级是否当前修改的上级
                res(node)
                function res(node) {
                    if(!shut) {
                        var n = node.parent
                        if(null != n) {
                            if(sf.id == n.data.id || sf.id == n.data.pid) {
                                shut = true
                            }
                            res(n)
                        }
                    }
                }
                if(shut == true) {
                    this.$message({
                        title: '提示', message: '选择所属上级有误',
                        type: 'warning', duration: 2000
                    })
                    return
                }

                this.formDepartment = Object.assign({}, this.formDepartment)
                this.formDepartment['pid'] = data.id
                this.formDepartment['parentName'] = data.name
            },
            handleIconClickDepartment(ev) {
                this.formDepartment = Object.assign({}, this.formDepartment)
                this.formDepartment['pid'] = ''
                this.formDepartment['parentName'] = ''
            },
            handleCloseDialogDepartment() {
                this.resetFormDepartment()
                this.detailDepartment = {
                    id: '',
                    pid: '',
                    name: '',
                    code: '',
                    remarks: '',
                    parentName: '',
                    companyId: '',
                    companyName: ''
                }
            },
            handleReloadDepartment(){
                this.getTreeDataDepartment()
            },
            resetFormDepartment() {
                if(this.$refs['formDepartment']) {
                    this.$refs['formDepartment'].resetFields()
                }
                this.formDepartment = {
                    id: '',
                    pid: '',
                    name: '',
                    code: '',
                    remarks: '',
                    parentName: '',
                    companyId: this.formDepartment.companyId,
                    companyName: this.formDepartment.companyName
                }
            },

            handleFilter() {//条件过滤
                this.listQuery.page = 1
                this.getTableData()
            },
            handleResetFilter() {//重置过滤条件
                this.$refs.filterForm.resetFields()
                this.getTableData()
            },
            handleSelectionChange(val) {//多选
                this.multipleSelection = val;
            },
            handleSizeChange(val) {
                this.listQuery.rows = val
                this.getTableData()
            },
            handleCurrentChange(val) {
                this.listQuery.page = val
                this.getTableData()
            },
            handleDelete(row) {//删除数据
                this.$confirm('确定要移除？', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    remove_department_user({ids: row.userCompanyDeptAssignId}).then(response => {
                        if(response.data.status) {
                            this.$notify({
                                title: '成功', message: response.data.message,
                                type: 'success', duration: 2000
                            })
                            this.getTableData()
                        } else {
                            this.$notify({
                                title: '发生错误', message: response.data.message,
                                type: 'error', duration: 2000
                            })
                        }
                    })
                }).catch(() => {
                    this.$message({ type: 'info', message: '已取消删除' })
                })
            },
            handleBatchDelete() {//批量删除数据
                this.$confirm('确定要删除？', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    if(this.multipleSelection.length > 0) {
                        let ids = []
                        for(let item of this.multipleSelection) {
                            ids.push(item.userCompanyDeptAssignId)
                        }
                        remove_department_user({ids: ids.join(',')}).then(response => {
                            if(response.data.status) {
                                this.$notify({
                                    title: '成功', message: response.data.message,
                                    type: 'success', duration: 2000
                                })
                                this.getTableData()
                            } else {
                                this.$notify({
                                    title: '发生错误', message: response.data.message,
                                    type: 'error', duration: 2000
                                })
                            }
                        })

                    } else {
                        this.$notify({
                            title: '提示', message: '请选择需要删除的记录',
                            type: 'warning', duration: 2000
                        })
                    }
                }).catch(() => {
                    this.$message({ type: 'info', message: '已取消删除' })
                })
            },
            getTableData() {
                this.listLoading = true
                selectList(this.listQuery).then(response => {
                    this.list = response.data.list
                    this.total = response.data.total
                    this.listLoading = false
                }).catch(error => {
                    console.log(error)
                    this.listLoading = false
                })
            }
        }
    }
</script>

<!-- 局部样式 -->
<style rel="stylesheet/scss" lang="scss" scoped>
    .card-header{
        border-bottom: 1px solid #d1dbe5; padding: 15px 20px 15px 7px;
    }
    .el-card__body{
        .el-tree{
            border: 0px;
        }
    }
</style>